<!DOCTYPE html>
<html>
<head>
  {include file="layout:_meta_index" /}
</head>
<body>

  <div class="layui-fluid">

    <div class="layui-card">
      <div class="layui-card-header">设置我的资料</div>
      <div class="layui-card-body" pad15>

        <div class="layui-form" lay-filter="">
          <div class="layui-form-item">
            <label class="layui-form-label">我的角色</label>
            <div class="layui-input-inline">
              <div id="xm-select"></div>
            </div>
            <div class="layui-form-mid layui-word-aux">当前角色不可更改为其它角色</div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
              <input type="text" name="username" value="{:isset($list.username)?$list.username:''}" readonly class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">不可修改。一般用于后台登入名</div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">真实姓名</label>
            <div class="layui-input-inline">
              <input type="text" name="admin_name" value="{:isset($list.admin_name)?$list.admin_name:''}" placeholder="请输入真实姓名" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-inline">
              <input type="text" name="email" lay-verify="emptyEmail" value="{:isset($list.email)?$list.email:''}" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-input-block">
              <input type="hidden" name="id" value="{:isset($list['id'])?$list['id']:''}">
              <input type="hidden" name="state" value="{:isset($list['state'])?$list['state']:''}">
              <input type="hidden" name="password" value="">
              <button class="layui-btn" lay-submit lay-filter="sysEdit">确认修改</button>
            </div>
          </div>
        </div>

      </div>
    </div>
  </div>

  {include file="layout:_footer" /}
  <script>
  layui.use(['index','form','xmSelect'],function () {
    var form = layui.form,$ = layui.$,xmSelect = layui.xmSelect;

    //角色多选框
    var xm_select = xmSelect.render({
      el: '#xm-select',
      tips: '请选择角色',
      prop: {name: 'title', value: 'id'},
      name: 'group_id',
      layVerify: 'required',
      disabled: true,
      data:[]
    });

    //获取数据以及赋值
    $.get("{:url('admin/info')}",function (res) {
      xm_select.update({data: res.roleList});
      xm_select.setValue(res.role)
    });

    form.verify({
      emptyEmail: function (value, item) { //value：表单的值、item：表单的DOM对象
        if(value){
          if(!(/^([A-Za-z0-9_\-\.\u4e00-\u9fa5])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,8})$/.test(value))){
            return '请输入合法的邮箱';
          }
        }
      }
    });

    form.on('submit(sysEdit)', function(obj){
      $.post("{:url('admin/info')}", obj.field, function (res) {
        var icon = 5;
        if (res.code) {
          icon = 6;
        }
        layer.msg(res.msg, {icon: icon, time: 1500});
      }, 'json');
    });

  });
  </script>
</body>
</html>